<?php
include ('chek.php');
//删除信息
$pid=$input->get('pid');
if($input->get('delete')=='del'){
    $sql="delete from page WHERE pid='{$pid}'";
    $is=$db->query($sql);
    if($is){
        header('location:blog.php');
    }else{
        die('删除失败!');
    }
}

//每一个页面显示的信息数
$po_number=$set_is['s_page'];
//获取当前的页面的page数
$page_num=(int) $input->get('page');
$page_num=$page_num<1?1:$page_num;
//获取数据总量
$pointer="select count(*) AS total from page";
$po_result=$db->query($pointer)->fetch_array(MYSQLI_ASSOC)['total'];
//分页
$parqisi=ceil($po_result/$po_number);
$m_page=($page_num-1)*$po_number;

//获取数据
$sql="select * from page ORDER by pid desc limit $m_page,$po_number";
$sql_result=$db->query($sql);
$rows=array();
while ($row=$sql_result->fetch_array(MYSQLI_ASSOC)){
    $rows[]=$row;
}
?>
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8" />
    <title>博客管理</title>
    <?php include (PATH.'/headr.php') ?>
</head>
<body>
<?php include ('nac.inc.php'); ?>
<div class="container">
    <div class="row">
        <h2>博客管理<small class="pull-right"><a class="btn btn-default" href="blog_add.php">添加博客</a></small></h2>
        <table class="table table-striped">
            <thead>
            <tr>
                <th>ID</th>
                <th>标题</th>
                <th>作者</th>
                <th>发布时间</th>
                <th>修改时间</th>
                <th>管理</th>
            </tr>
            </thead>
            <tbody>
            <?php foreach ($rows as $row) :?>

                <?php
                $itm=date('Y-m-d H:s:i',$row['intime']);
                $utm=date('Y-m-d H:s:i',$row['uptime']);
                ?>

                <tr>
                    <td><?php echo $row['pid'];?></td>
                    <td><?php echo $row['title'];?></td>
                    <td><?php echo $row['aptor'];?></td>
                    <td><?php echo $itm;?></td>
                    <td><?php echo $utm;?></td>
                    <td>
                        <a href="blog_add.php?pid=<?php echo $row['pid'];?>">修改</a>
                        <a onclick="return confirm('确定删除吗？')" href="blog.php?delete=del&pid=<?php echo $row['pid'];?>">删除</a>
                    </td>
                </tr>
            <?php endforeach ;?>
            </tbody>
        </table>
        <!-- 分页 -->
        <nav aria-label="Page navigation">
            <ul class="pagination">
                <?php
                $href='<li><a href="blog.php?page=%d">%s</a></li>';
                for($i=1;$i<=$parqisi;$i++) {
                    ?>
                    <?php echo sprintf($href,$i,"第{$i}页")?>
                <?php
                }
                ;?>
            </ul>
        </nav>
    </div>
</div>
</body>
</html>